package com.nb.hdj.testCase.consultModule;

import com.nb.hdj.baseClass.SeleniumUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

/**
 * @Description: 更改咨询测试用例
 * @Author: hedongjia
 * @Date: 2021/11/23 下午2:48
 * @Version: v1.0
 */
public class UpdateConsultCase extends ConsultCaseBase{
    private String content="更改咨询标题自动化测试";
    /**
     * 更改咨询测试用例
     * @param driver
     * @return
     */
    public boolean updateConsult(WebDriver driver){
        try {
            //切换到未发布 编辑咨询
            seleniumUtil.elementClick(driver, By.xpath(consultMap.get("NotReleasePublishElement")));
            Thread.sleep(500);
            //点击第一行元素 默认为刚刚新增的咨询
            seleniumUtil.elementClick(driver, By.xpath(consultMap.get("FirstLineElement")));
            Thread.sleep(500);
            //点击编辑
            seleniumUtil.elementClick(driver, By.xpath(consultMap.get("EditorElement")));
            Thread.sleep(1000);
            //更改咨询标题
            seleniumUtil.elementClick(driver, By.xpath(consultMap.get("EditorTitleBeforeElement")));
            Thread.sleep(300);
            seleniumUtil.elementClear(driver,By.xpath(consultMap.get("EditorTitleBeforeElement")));
            Thread.sleep(300);
            //输入
            seleniumUtil.elementSendKeys(driver,By.xpath(consultMap.get("EditorTitleAfterElement")),content);
            Thread.sleep(500);
            //点击确定
            seleniumUtil.elementClick(driver, By.xpath(consultMap.get("EditorYesElement")));
            Thread.sleep(500);
            //点击返回
            seleniumUtil.elementClick(driver, By.xpath(consultMap.get("EditorReturnElement")));
            if(seleniumUtil.elementTextIsEqual(driver,By.xpath(consultMap.get("FirstLineElement")),content)){
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 删除咨询用例
     * @param driver
     * @return
     */
    public boolean deleteConsult(WebDriver driver){
        try {
            Thread.sleep(500);
            seleniumUtil.elementClick(driver, By.xpath(consultMap.get("DeleteFirstElement")));
            //点击删除按钮
            Thread.sleep(500);
            seleniumUtil.elementClick(driver, By.xpath(consultMap.get("DeleteButtonElement")));
            //点击确定
            seleniumUtil.elementClick(driver, By.xpath(consultMap.get("DeleteYesElement")));
            Thread.sleep(500);
            //String firstLineElement = seleniumUtil.getElementText(driver, By.xpath(consultMap.get("FirstLineElement")));
            //System.out.println(firstLineElement);
            //判断是否删除
            if(!seleniumUtil.elementTextIsEqual(driver,By.xpath(consultMap.get("PublishFirstLineElement")),content)){
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }

}
